package com.orientsec.autotest.project.system.systemExpression.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.systemExpression.domain.SystemExpression;
import com.orientsec.autotest.project.system.systemExpression.service.ISystemExpressionService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 达式信息操作处理
 * 
 * @author autotest
 * @date 2019-12-18
 */
@Controller
@RequestMapping("/system/systemExpression")
public class SystemExpressionController extends BaseController
{
    private String prefix = "system/systemExpression";
	
	@Autowired
	private ISystemExpressionService systemExpressionService;
	
	@RequiresPermissions("system:systemExpression:view")
	@GetMapping()
	public String systemExpression()
	{
	    return prefix + "/systemExpression";
	}
	
	/**
	 * 查询达式列表
	 */
	@RequiresPermissions("system:systemExpression:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SystemExpression systemExpression)
	{
		startPage();
        List<SystemExpression> list = systemExpressionService.selectSystemExpressionList(systemExpression);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出达式列表
	 */
	@RequiresPermissions("system:systemExpression:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SystemExpression systemExpression)
    {
    	List<SystemExpression> list = systemExpressionService.selectSystemExpressionList(systemExpression);
        ExcelUtil<SystemExpression> util = new ExcelUtil<SystemExpression>(SystemExpression.class);
        return util.exportExcel(list, "systemExpression");
    }
	
	/**
	 * 新增达式
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存达式
	 */
	@RequiresPermissions("system:systemExpression:add")
	@Log(title = "达式", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SystemExpression systemExpression)
	{		
		return toAjax(systemExpressionService.insertSystemExpression(systemExpression));
	}

	/**
	 * 修改达式
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		SystemExpression systemExpression = systemExpressionService.selectSystemExpressionById(id);
		mmap.put("systemExpression", systemExpression);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存达式
	 */
	@RequiresPermissions("system:systemExpression:edit")
	@Log(title = "达式", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SystemExpression systemExpression)
	{		
		return toAjax(systemExpressionService.updateSystemExpression(systemExpression));
	}
	
	/**
	 * 删除达式
	 */
	@RequiresPermissions("system:systemExpression:remove")
	@Log(title = "达式", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(systemExpressionService.deleteSystemExpressionByIds(ids));
	}
	
}
